import math
from typing import Tuple

from PIL import Image

img = Image.new('RGB', (400, 400), (255, 255, 255))

pim = img.load()


def div_8(cpos: Tuple[int, int], x: int, y: int, e: float):
    cx, cy = cpos
    cp = int(e * 255)
    c = (cp, cp, cp)
    pim[cx + x, cy + y] = c
    pim[cx + y, cy + x] = c

    pim[cx + y, cy - x] = c #关于y=x对称
    pim[cx + x, cy - y] = c

    pim[cx - x, cy - y] = c
    pim[cx - y, cy - x] = c

    pim[cx - y, cy + x] = c
    pim[cx - x, cy + y] = c

r = 100
cpos = (200, 200)
y = r
x = 0
e = 0
while x <= y:
    e = y - math.sqrt(r*r - (x + 1) * (x + 1))
    if e >= 1:
        e -= 1
        y -= 1
    div_8(cpos, x, y, e)
    div_8(cpos, x, y - 1, 1 - e)

    x+=1

img.save('a.png', 'png')
